<article class="cl pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-save">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">
                <span class="c-red">*</span>原密码：</label>
            <div class="formControls col-xs-8 col-sm-4">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="初始密码"
                    id="oldpassword" name="oldpassword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">
                <span class="c-red">*</span>新密码：</label>
            <div class="formControls col-xs-8 col-sm-4">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="请输入新密码"
                    id="newpassword" name="newpassword">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">
                <span class="c-red">*</span>确认密码：</label>
            <div class="formControls col-xs-8 col-sm-4">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="请再次输入新密码"
                    id="repassword" name="repassword">
            </div>
            <div class="col-3"> </div>
        </div>
        <div class="row cl" style="margin-top: 80px;">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-success radius" type="button"
                    id="form-save-button">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button class="btn btn-default radius" type="button" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;
            </div>
        </div>
    </form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $("#form-save-button").click(function () {
        var oldpassword = $("#oldpassword").val();
        var newpassword = $("#newpassword").val();
        var repassword = $("#repassword").val();

        if (isNull(oldpassword)) {
            layer.msg('* 原密码不能为空', {
                icon: 5,
                time: 1000
            });
            return false;
        }

        if (!pwdFormat6Mix(newpassword)) {
            layer.msg('* 密码6位及以上, 至少包括字母和数字', {
                icon: 5,
                time: 1000
            });
            return false;
        }

        if (newpassword != repassword) {
            layer.msg('* 两次密码不一致,请重新输入', {
                icon: 5,
                time: 1000
            });
            return false;
        }

        $.ajax({
            type: 'POST',
            url: '{:url("password")}',
            data: {
                oldpassword: oldpassword,
                newpassword: newpassword,
                repassword: repassword,
            },
            dataType: 'json',
            success: function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, { icon: 1 }, function () {
                        parent.location.reload(); // 父页面刷新
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 1000
                    });
                    return false;
                }
            }
        })
    })
</script>
<!--请在上方写此页面业务相关的脚本-->